package myTest.syntax

import myTest.example.Expr
import myTest.example.Num
import myTest.example.Sum

class If {

    /**
     *  不存在三元运算符
     *  if下只有一句代码{}大括号可以不加
     */
    fun getExpr(expr: Expr):String=

        if (expr is Num)
            "num"
        else if (expr is Sum)
            "sum"
        else
            ""

        //使用when代替上面语句
//        when(expr){
//            is Num->"num"
//            is Sum->"sum"
//            else ->""
//        }

}



fun main(args: Array<String>) {
    println(If().getExpr(Sum(Num(1),Num(2))))

    //in检查区间成员,不限于字符，任意实现Comparable接口
    println(isNum('2'))
    //when  in
    println(type('a'))

    println("Kotlin" in "Java".."Scala")

}


fun isNum(char: Char)=char in '0'..'9'

fun type(char: Char)=when(char){
    in '0'..'9'->"数字"
    in 'a'..'z',in 'A'..'Z'->"字母"
    else ->"未知"
}
